package com.song.ssm.ssmvueproject.controller;

import com.song.ssm.ssmvueproject.entity.R;
import com.song.ssm.ssmvueproject.pojo.LoginVo;
import com.song.ssm.ssmvueproject.utils.JwtUtils;
import com.song.ssm.ssmvueproject.utils.RedisTemplate;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author TonySong
 * @date 2024/4/2 0002
 * @time 14:21
 */
@RestController
public class TestController {

    @Resource
    private RedisTemplate redisTemplate;
    @GetMapping("/test")
    public String test(){
        this.redisTemplate.set("t1","八戒",10000L);
        this.redisTemplate.setObject("map", List.of(1,2,3,4,5,6,7,8,9,10),10000L);
        return "test";
    }

    @PostMapping("/login")
    public R login(@RequestBody LoginVo loginVo){
        String username = loginVo.getUsername();
        String password = loginVo.getPassword();
        System.err.println(username);
        System.err.println(password);
        if(username.equals("admin") && password.equals("1234")){
            loginVo.setToken(JwtUtils.createToken());
            return R.success(loginVo);
        }
        return R.error(303,"用户名或密码错误");
    }
}
